//888888888888888888888888888888888888888888888888888888888888888888888888888888888888888
//
//	File		 :	ResidueGroup.h
//	Contents	 :	Header file for class CResidueGroupInfo
//					Configuration information for formattting consensus sequences
//					Each group of residues of a particular type is assigned a format
//						which is applied if there is a consensus.
//	Creation Date:	26/12/1999
//	Last Modified:	27/12/1999	lg
//	tabs width	 :	every 4 characters
//
//888888888888888888888888888888888888888888888888888888888888888888888888888888888888888

#if !defined(RESIDUEGROUP_H)
#define RESIDUEGROUP_H

#include <istream>
#include <algorithm>
#include <string.h>
#include "formattedoutput.h"
#include "std_helper.h"
template<class T, class C> class CBinary_basic_ostream;
typedef CBinary_basic_ostream<std::ostream, char> CBinary_ostream;
template<class T, class C> class CBinary_basic_istream;
typedef CBinary_basic_istream<std::istream, char> CBinary_istream;

class CResidueGroupInfo
{
public:
	CResidueGroupInfo(){}
	CResidueGroupInfo(const std::string& name);
	typedef CFormattedOutput::CTextFormat CTextFormat;
	std::string			Name;
	std::string			Residues;
	CTextFormat			Format;
	bool				Active;
	char				Marker;
};

//_______________________________________________________________________________________
//
//		Constructor
//
//_______________________________________________________________________________________
inline CResidueGroupInfo::CResidueGroupInfo(const std::string& name)
{
	Name	 = name;
	Residues = "";
	Marker	 = ' ';
	Active	 = true;
	Format.Set(0);
}


struct CResidueGroupsInfo
{
	typedef CFormattedOutput::CTextFormat CTextFormat;

	// public data
	std::vector<CResidueGroupInfo>	
							ResGrps;
	std::string				TextFont;
	unsigned				TextSizeInTenths;

	// handling parsing errors
	unsigned				GetParsingErrorLineNumber() const;
	const std::string&		GetLastErrorStr() const				 {	return ErrorStr;	}

	bool					Read(std::istream& );
	bool					GetResidueGrpsFormats(CFormatVec& formats,
												   std::vector<std::string>& residues_sets,
												   std::string& markers) const;
	void					GetResidueGrpsFormats(CFormatVec& formats) const;
	bool					IS_VALID() const;

private:
	unsigned				ErrorLineNumber;
	std::string				ErrorStr;
	bool					ReadInitialData(std::istream& is);
	bool					ReadResidueData(std::istream& is);
	friend std::ostream& operator << (std::ostream& os, const CResidueGroupsInfo& i);
	friend CBinary_ostream& operator << (CBinary_ostream& os, const CResidueGroupsInfo& r);
	friend CBinary_istream& operator >> (CBinary_istream& is, CResidueGroupsInfo& r);
	void Write(std::ostream& is) const;	// text format
};

std::ostream& operator << (std::ostream& os, const CResidueGroupsInfo& i);
CBinary_ostream& operator << (CBinary_ostream& os, const CResidueGroupsInfo& r);
CBinary_istream& operator >> (CBinary_istream& is, CResidueGroupsInfo& r);

	

//_______________________________________________________________________________________
// inlines
//_______________________________________________________________________________________
inline unsigned CResidueGroupsInfo::GetParsingErrorLineNumber() const
{
	return ErrorLineNumber;
}
inline bool CResidueGroupsInfo::IS_VALID() const
{
	if (ResGrps.size() < 2)
		return false;
	if (TextFont.length() == 0)
		return false;
	if (TextSizeInTenths == 0 || TextSizeInTenths > 1440)
		return false;
	if (stricmp( ResGrps[0].Name, "Default")  != 0)
		return false;
	if (stricmp( ResGrps[1].Name, "Single")  != 0)
		return false;
	if (ResGrps[0].Residues != "X" || ResGrps[1].Residues != "X")
		return false;
	if (!ResGrps[0].Active)
		return false;
	return true;
}

#endif // !defined(RESIDUEGROUP_H)
